<%--
  Created by IntelliJ IDEA.
  User: Acer
  Date: 2020/9/14
  Time: 20:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="rapid" uri="http://www.rapid-framework.org.cn/rapid" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<rapid:override name="head">
    <title>课程列表</title>
</rapid:override>

<rapid:override name="content">

    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>

    <form class="layui-form" style="margin:10px 15px 10px;">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <div style="display: inline-block">
                    <div style="width: 180px; float: left; margin-left:-100px;">
                        <select class="layui-select" id="teaId">
                            <option value="0">教师姓名</option>
                            <c:forEach items="${teaList}" var="teacher">
                                <option value="${teacher.teaId}">${teacher.teaName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <button type="button" id="tea" class="layui-btn" style="margin-left:10px;">筛选</button>
                </div>
                <div style="display: inline-block">
                    <div style="width: 180px; float: left; margin-left:300px;">
                        <select class="layui-select" id="insId">
                            <option value="0">学院名称</option>
                            <c:forEach items="${insList}" var="institution">
                                <option value="${institution.insId}">${institution.insName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <button type="button" id="ins" class="layui-btn" style="margin-left:10px;">筛选</button>
                </div>
                <button type="button" class="layui-btn" style="float:right;" id="searchCourse">搜索</button>
                <input type="text" id="search" class="layui-input" style="float:right; width:200px;"
                       placeholder="请输入课程编号">
            </div>
        </div>
    </form>
        <p>${msg}</p>

        <div class="layui-form" style="margin:10px 15px 10px;">
            <table class="layui-table">
                <colgroup>
                    <col width="100">
                    <col width="120">
                    <col width="80">
                    <col width="50">
                    <col width="50">
                    <col width="200">
                    <col width="60">
                </colgroup>
                <thead>
                    <tr>
                        <th>课程编号</th>
                        <th>课程名称</th>
                        <th>教师名称</th>
                        <th>人数限制</th>
                        <th>已选人数</th>
                        <th>学院限制</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>

                        <c:forEach items="${paging.dataList}" var="course">
                        <tr>
                            <td>${course.classId}</td>
                            <td>${course.className}</td>
                            <td>${course.teaName}</td>
                            <td>${course.classNum}</td>
                            <td>${course.classChooseNum}</td>
                            <td>
                                <c:forEach items="${course.classLimitInsName}" var="ins">
                                    ${ins};
                                </c:forEach>
                            </td>
<%--                            <td>--%>
<%--                                <c:choose>--%>
<%--                                    <c:when test="${course.classNum == course.classChooseNum}">--%>
<%--                                        <button class="layui-btn" disabled onclick="detail_fun(${course.classId})">选择</button>--%>
<%--                                    </c:when>--%>
<%--                                    <c:when test="${course.isChoose == 1}">--%>
<%--                                        <button class="layui-btn" disabled onclick="detail_fun(${course.classId})">已选</button>--%>
<%--                                        <button class="layui-btn" onclick="delete_fun(${course.classId})" >退课</button>--%>
<%--                                    </c:when>--%>

<%--                                    <c:otherwise>--%>
<%--                                        <button class="layui-btn" onclick="detail_fun(${course.classId})">选择</button>--%>
<%--                                    </c:otherwise>--%>
<%--                                </c:choose>--%>
<%--                            </td>--%>
                            <td>
                                <c:choose>
                                    <c:when test="${course.classNum==course.classChooseNum}">
                                        <button class="layui-btn" onclick="detail_fun(${course.classId})" disabled
                                                style="background-color: gray;">选择
                                        </button>
                                    </c:when>
                                    <c:when test="${course.isChoose==1}">
                                        <button class="layui-btn" onclick="detail_fun(${course.classId})" disabled
                                                style="background-color: gray;">已选
                                        </button>
                                        <button class="layui-btn" onclick="delete_fun(${course.classId})">退课
                                        </button>
                                    </c:when>
                                    <c:otherwise>
                                        <button class="layui-btn" onclick="detail_fun(${course.classId})">选择
                                        </button>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                        </c:forEach>

                </tbody>
            </table>

            <div style="text-align:center; margin-top:10px; margin-left:-100px;">
                <c:if test="${paging.totalPage >= 0}">
                    <p style=" color: black; font-size:16px; margin-bottom:10px;">当前第${paging.currentPage}页/共${paging.totalPage}页</p>
                    <c:choose>
                        <c:when test="${paging.totalPage==0}">
                            <%--  将按钮放到表单外面就不用担心点击事件的地址和表单的提交地址重复啦                         --%>
                            <button class="layui-btn layui-btn-disabled" onclick="go(1)">首页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.currentPage-1})">上一页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.currentPage+1})">下一页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.totalPage})">末页</button>
                        </c:when>
                        <c:when test="${paging.currentPage==1 && paging.totalPage==1}">
                            <button class="layui-btn" onclick="go(1)">首页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.currentPage-1})">上一页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.currentPage+1})">下一页</button>
                            <button class="layui-btn" onclick="go(${paging.totalPage})">末页</button>
                        </c:when>
                        <c:when test="${paging.currentPage==1 && paging.totalPage>1}">
                            <button class="layui-btn" onclick="go(1)">首页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.currentPage-1})">上一页</button>
                            <button class="layui-btn" onclick="go(${paging.currentPage+1})">下一页</button>
                            <button class="layui-btn" onclick="go(${paging.totalPage})">末页</button>
                        </c:when>
                        <c:when test="${paging.currentPage>1 && paging.currentPage<paging.totalPage}">
                            <button class="layui-btn" onclick="go(1)">首页</button>
                            <button class="layui-btn" onclick="go(${paging.currentPage-1})">上一页</button>
                            <button class="layui-btn" onclick="go(${paging.currentPage+1})">下一页</button>
                            <button class="layui-btn" onclick="go(${paging.totalPage})">末页</button>
                        </c:when>
                        <c:when test="${paging.currentPage>1 && paging.currentPage==paging.totalPage}">
                            <button class="layui-btn" onclick="go(1)">首页</button>
                            <button class="layui-btn" onclick="go(${paging.currentPage-1})">上一页</button>
                            <button class="layui-btn layui-btn-disabled" onclick="go(${paging.currentPage+1})">下一页</button>
                            <button class="layui-btn" onclick="go(${paging.totalPage})">末页</button>
                        </c:when>
                    </c:choose>
                </c:if>
            </div>
        </div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>

    <script>
        function go(page) {
            console.log(90);
            window.location.href = "<%=basePath%>student/courseList?page="+page;
        }
        // 课程详细信息
        function detail_fun(classId) {
            console.log(classId);
            window.location.href = "<%=basePath%>student/courseDetail?classId="+classId;
        }
        // 退课
        function delete_fun(classId) {
            let r = confirm("你确认退课吗？");
            if(r) {
                window.location.href = "<%=basePath%>student/deleteCourse?classId="+classId;
            } else {
                return ;
            }
        }


        $(function () {
            $('#tea').click(function () {
                let teaId = $('#teaId option:selected').attr("value");
                console.log(teaId);
                if(teaId === 0) {
                    alert("请选择正确的教师姓名:");
                } else {
                    window.location.href = "<%=basePath%>student/searchListByTeaId?teaId="+teaId;
                }
            })

            $('#ins').click(function() {
                let insId = $('#insId option:selected').attr("value");
                console.log(insId);
                if(insId === 0) {
                    alert("请选择正确的学院名称:")
                } else {
                    window.location.href = "<%=basePath%>student/searchListByInsId?insId="+insId;
                }
            })

            $('#searchCourse').click(function () {
                let classId = $('#search').val();
                window.location.href = "<%=basePath%>student/searchCourse?classId="+classId;
            })
        })

    </script>
</rapid:override>

<%@include file="base.jsp"%>
